import axios from "../plugin/http";

export default {
  getUsers(cb, errorCb) {
    axios
      .get("/api/user")
      .then(result => {
        cb(result.data);
      })
      .catch(err => {
        errorCb(err);
      });
  },
  updateUser(payload, cb, errorCb) {
    // debugger;
    axios
      .put(`/api/user/${payload._id}/`, {
        "header": {
          "sysCode": "IDS",
          "platform": window.navigator.platform,
          "timestamp": new Date().getTime()
        },
        "payload": {
          "username": payload.username,
          "phonenum": payload.phonenum,
          "email": payload.email,
        }
      })
      .then(result => {
        cb(result.data);
      })
      .catch(err => {
        errorCb(err);
      });
  },
  insertUser(payload, cb, errorCb) {
    axios
      .post(`/api/user/`, {
        "header": {
          "sysCode": "IDS",
          "platform": window.navigator.platform,
          "timestamp": new Date().getTime()
        },
        payload
      })
      .then(result => {
        cb(result.data);
      })
      .catch(err => {
        errorCb(err);
      });
  },
  deleteUser(payload, cb, errorCb) {
    axios
      .delete(`/api/user/${payload._id}`, {
        "header": {
          "sysCode": "IDS",
          "platform": window.navigator.platform,
          "timestamp": new Date().getTime()
        },
      })
      .then(result => {
        cb(result.data);
      })
      .catch(err => {
        errorCb(err);
      });
  }
}
